
function getXMLHttpRequest() {
	var xhr = null;
	
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
		return null;
	}
	
	return xhr;
}

function update_projet()
{
   
	var http = getXMLHttpRequest();
  var div = document.getElementById("modif_projet_erreur");
	var mobile = document.getElementById("mobile").value;
	var description = document.getElementById("description").value;
	http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
			div.innerHTML = http.responseText;			
		}
	};
	http.open('post', 'actions_eleve/projet.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "async_update=1&mobile="+mobile+"&description="+description;		
	http.send(data);
}

function update_profil()
{
   
	var http = getXMLHttpRequest();
  var div = document.getElementById("modif_profil_form");
	var login = document.getElementById("login").value;
	var mot_de_passe = document.getElementById("mot_de_passe").value;
  var mobile = document.getElementById("mobile").value;
	var description = document.getElementById("description").value;
	http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
			div.innerHTML = http.responseText;	
		}
	};
 
	http.open('post', 'actions_eleve/fiche_eleve_action.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "async_update=1&login="+login+"&mot_de_passe="+mot_de_passe+"&mobile="+mobile+"&description="+description;		
  http.send(data);
}

function creer_seance()
{
	var http = getXMLHttpRequest();
  var erreur_div = document.getElementById("creer_seance_erreur_div");
  var atelier_div = document.getElementById("ajout_atelier_seance");
  var date_input = document.getElementById("date_seance");
  var calendrier_button = document.getElementById("date_bouton");
  var creer_seance_button = document.getElementById("creer_seance_bouton");
	var date_seance = date_input.value;
	
	http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
      if( http.responseText.indexOf("Erreur",0) >= 0 )
			  erreur_div.innerHTML = http.responseText;			
      else
      {
			  erreur_div.innerHTML = http.responseText;			
        date_input.disabled = true;
        calendrier_button.disabled = 'disabled';
        creer_seance_button.disabled = 'disabled';
        atelier_div.style.display = 'block';
      }
		}
	};
	http.open('post', 'actions_eleve/ajout_seance.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "creer_seance=1&date_seance="+date_seance;		
	http.send(data);
}

function ajout_atelier_seance()
{
	var http = getXMLHttpRequest();
  var id_seance = document.getElementById("id_seance").value;
  var id_atelier = document.getElementById("select_atelier").value;
  var erreur_div = document.getElementById("ajout_atelier_seance_erreur_div");
	
	http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
			  erreur_div.innerHTML = http.responseText;			
        generer_ateliers_div();
		}
	};
	http.open('post', 'actions_eleve/ajout_seance.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "ajout_atelier=1&id_seance="+id_seance+"&id_atelier="+id_atelier;		
	http.send(data);
}

function generer_ateliers_div()
{
	var http = getXMLHttpRequest();
  var id_seance = document.getElementById("id_seance").value;
  var div = document.getElementById("ateliers_seances_div");
	
	http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
			  div.innerHTML = http.responseText;			
		}
	};
	http.open('post', 'actions_eleve/ajout_seance.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "generer_ateliers=1&id_seance="+id_seance;		
	http.send(data);
}

function ajouter_exercice_seance(id_atelier_projet_seance)
{
	var http = getXMLHttpRequest();
  var serie = document.getElementById(id_atelier_projet_seance+"_serie").value;
  var repetition = document.getElementById(id_atelier_projet_seance+"_repetition").value;
  var charge = document.getElementById(id_atelier_projet_seance+"_charge").value;
  var erreur_div = document.getElementById(id_atelier_projet_seance+"_erreur_div");
	
	http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
      if( http.responseText.indexOf("Erreur",0) >= 0 )
			  erreur_div.innerHTML = http.responseText;			
      else
        generer_ateliers_div();
		}
	};
	http.open('post', 'actions_eleve/ajout_seance.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "ajouter_exercice=1&id_atelier_projet_seance="+id_atelier_projet_seance+"&serie="+serie+"&repetition="+repetition+"&charge="+charge;		
	http.send(data);
} 

function creer_bilan()
{
  var insert_seance_button = document.getElementById("insert_seance_button");
  var select_seance = document.getElementById("select_seance");
  var atelier_div = document.getElementById("ajout_atelier_seance");
  var bilan_div = document.getElementById("bilan_seance_div");

  select_seance.disabled = 'disabled';
  insert_seance_button.disabled = 'disabled';
  atelier_div.style.display = 'block';
  bilan_div.style.display = 'block';
}

function ajout_atelier_bilan()
{
	var http = getXMLHttpRequest();
  var id_seance = document.getElementById("select_seance").value;
  var id_atelier = document.getElementById("select_atelier").value;
  var erreur_div = document.getElementById("ajout_atelier_seance_erreur_div");
	
	http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
			  erreur_div.innerHTML = http.responseText;			
        generer_ateliers_bilan_div();
		}
	};
	http.open('post', 'actions_eleve/ajout_bilan.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "ajout_atelier=1&id_seance="+id_seance+"&id_atelier="+id_atelier;		
	http.send(data);
}

function generer_ateliers_bilan_div()
{
	var http = getXMLHttpRequest();
  var id_seance = document.getElementById("select_seance").value;
  var div = document.getElementById("ateliers_seances_div");
	
	http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
			  div.innerHTML = http.responseText;			
		}
	};
	http.open('post', 'actions_eleve/ajout_bilan.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "generer_ateliers=1&id_seance="+id_seance;		
	http.send(data);
}

function ajouter_exercice_bilan(id_atelier_bilan_seance)
{
	var http = getXMLHttpRequest();
  var serie = document.getElementById(id_atelier_bilan_seance+"_serie").value;
  var repetition = document.getElementById(id_atelier_bilan_seance+"_repetition").value;
  var charge = document.getElementById(id_atelier_bilan_seance+"_charge").value;
  var erreur_div = document.getElementById(id_atelier_bilan_seance+"_erreur_div");
	
	http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
      if( http.responseText.indexOf("Erreur",0) >= 0 )
			  erreur_div.innerHTML = http.responseText;			
      else
        generer_ateliers_bilan_div();
		}
	};
	http.open('post', 'actions_eleve/ajout_bilan.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "ajouter_exercice=1&id_atelier_bilan_seance="+id_atelier_bilan_seance+"&serie="+serie+"&repetition="+repetition+"&charge="+charge;		
	http.send(data);
} 

function ajout_bilan()
{
  var id_seance = document.getElementById("select_seance").value;
  var ressenti = document.getElementById("ressenti").value;
  var commentaire = document.getElementById("commentaire").value;
	var http = getXMLHttpRequest();
  var erreur_div = document.getElementById("bilan_seance_erreur_div");
	
	http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
		  erreur_div.innerHTML = http.responseText;			
		}
	};
	http.open('post', 'actions_eleve/ajout_bilan.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "ajout_bilan=1&id_seance="+id_seance+"&ressenti="+ressenti+"&commentaire="+commentaire;		
	http.send(data);
}

function evolution_valide(){
  var atelier = document.getElementById("atelier");
    
  var div_error = document.getElementById("error_div");
  var div_graph = document.getElementById("graph");
  div_graph.innerHTML = "";
 
  var http = getXMLHttpRequest(); 
  http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
      var response = http.responseText;
      var erreur = response.indexOf("Erreur",0);
		if( erreur < 0 )
		{
        div_graph.innerHTML = http.responseText;	
        div_error.innerHTML = "";		
        
      }else	
        div_error.innerHTML = http.responseText;			
		}
	};
	http.open('post', 'actions_eleve/evolution_graph.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "type=graph&id_atelier="+atelier.value;		
	http.send(data);  
}

function valid_bilan_eleve() {
  var div_seance = document.getElementById("div_seance");    
  var div_error = document.getElementById("div_error");
  var seance = document.getElementById("seance");

  var http = getXMLHttpRequest(); 
  http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
      var response = http.responseText;
      
      var erreur = response.indexOf("Erreur",0);
      if( erreur < 0 )
      {
        div_seance.innerHTML = http.responseText;	
        div_error.innerHTML = "";		
        
      }else	
        div_error.innerHTML = http.responseText;			
		}
	};
	http.open('post', 'actions_eleve/liste_bilan.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "type=bilan&id_seance="+seance.value;
	http.send(data);  
  
}

function voir_fiche_atelier()
{
	var http = getXMLHttpRequest();
  var id_atelier = document.getElementById("id_atelier").value;

  http.onreadystatechange = function()
	{
		if (http.readyState == 4)
		{
			document.getElementById("details_atelier").innerHTML = http.responseText;			
		}
	};
	http.open('post', 'actions_eleve/fiche_atelier.php', true);
	http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	data = "voir_fiche=1&id_atelier="+id_atelier;		
	http.send(data);
}
